
// A5_crosswalk_k
//==============================================================================

// Description: This code crosswalks the data to the product categories that are 
// used on the supply side

clear

cd "D:\data_replication"

// Import product_id to k mapping to Stata and save
//==============================================================================

import delimited estimation\4_demand_estimation\pc8plus_i_k.csv, clear 
keep v1 v3
rename v1 product_id
rename v3 k
save data\number_firms\pc8plus_i_k.dta, replace


// Crosswalk companies by product_id to companies by k 
//==============================================================================

use data\number_firms\companies_product_id.dta, clear
merge m:1 product_id using data\number_firms\pc8plus_i_k.dta
replace companies_product_id = 1 if _merge == 2                                 // Set companies to 1 for missing categories
replace declarant = 1 if _merge == 2
keep declarant k companies_product_id
drop if k == 0
drop if k == .
order k declarant companies_product_id
sort k declarant
rename companies_product_id companies_k
save data\number_firms\companies_k.dta, replace
export delimited using data\number_firms\companies_k.csv, replace
